import 'dart:typed_data';

import 'response_data_base.dart';

class LorinResponseData extends ResponseDataBase {
  // 响应数据
  // 第一个字节是响应码，后续字节是实际数据
  final Uint8List _rsp;

  // 是否只有状态码的响应
  final bool onlyStatusRsp;

  // 成功码
  final int successCode;

  LorinResponseData({
    required Uint8List rsp,
    this.onlyStatusRsp = false,
    this.successCode = 0x00,
  }) : _rsp = rsp;

  @override
  Uint8List get data => onlyStatusRsp ? Uint8List(0) : _rsp;

  @override
  int get code => _rsp.isNotEmpty ? _rsp.first : -1;

  @override
  bool get isSuccess => onlyStatusRsp
      ? code == successCode
      : true; // 当onlyStatusRsp为true时，判断code是否等于successCode，否则默认成功
}
